home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Sample code demonstrating detecting a CD
- **
- ** by Brian Bechtel, Apple Developer Technical Support
- **
- ** File: identifyCD.c
- **
- ** Copyright © 1995 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DTS Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- */
-
- #include <Devices.h>
- #include <Files.h>
- #include "identifyCD.h"
-
- /*
- * use this version of a Control structure for a ReadTOC call
- */
- typedef struct {
- struct QElem *qLink;
- short qType;
- short ioTrap;
- Ptr ioCmdAddr;
- ProcPtr ioCompletion;
- OSErr ioResult;
- char *ioNamePtr;
- short ioVRefNum;
- short ioCRefNum;
- short csCode;
- unsigned long discID;
- char unused[18];
- } CDTOCParam;
-
- enum {
- kReadTOC = 100
- };
-
- /************************************************************************
- *
- * Function: IDDisc
- *
- * Purpose: return total time on this disc as unique ID
- *
- * Returns: OSErr
- * either noErr if everything was okay
- * or some parameter error from driver call.
- *
- * Side Effects:
- * fills in discID
- *
- * Description:
- * call the driver ReadTOC call to get lead-out time.
- * Return this time as the unique id for this disc.
- *
- ************************************************************************/
- OSErr IDDisc(short refNum, unsigned long *discID)
- {
- CDTOCParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 0;
- myPB.ioCRefNum = refNum;
- myPB.csCode = kReadTOC;
- myPB.discID = 0x00020000; /* request lead-out time */
-
- result = PBControlSync((ParmBlkPtr)&myPB);
-
- if (result == noErr)
- *discID = myPB.discID >> 8;
- else
- *discID = 0;
- return result;
- }
-
-